﻿/// <reference path="jquery-1.8.2.min.js" />
/// <reference path="animation.js" />
/// <reference path="site.js" />
/// <reference path="menu.js" />
/// <reference path="data.js" />
/// <reference path="templating.js" />

site.portfolio = {
    
    // From site contract: called when the application is ready
    InitializeComponent: function () {
        // Registers portfolio mini template
        site.templating.templates.portfolioMiniItemTemplate = new DataTemplate({ uri: "../templates/portfolioMiniItemTemplate.htm" });
        site.templating.templates.portfolioContentTemplate = new DataTemplate({ uri: "../templates/portfolioContentTemplate.htm" });
        site.data.items.portfolioItems = new DataJson({ uri: "../data/portfolio.json" });
    },
    
    /// From site contract: called when all registered templates are loaded
    OnTemplateLoaded: function () {
        //alert(site.templating.templates.portfolioMiniItemTemplate.LoadContent({ title: "title1" }));
    },
    
    /// From site contract: called when all registered data items are loaded
    OnDataLoaded: function () { },
    
    /// From site contract: called when while elements are available
    OnReady: function () {
        if (site.portfolio.isOpen) { site.portfolio.Open(); }
        //alert(site.data.items.portfolioItems.content);
    },
    
    /// From menu contract: called when the menu open this category
    Open: function () {
        site.portfolio.isOpen = true;
        //alert(site.data.items.portfolioItems.content);
        var htmlItems = [];
        for (var item in site.data.items.portfolioItems.content) {
            var currentItem = site.data.items.portfolioItems.content[item];
            htmlItems.push(site.templating.templates.portfolioMiniItemTemplate.LoadContent(currentItem));
        }
        var htmlContent = new function () { };
        htmlContent.Content = htmlItems.join("");
        $("#Content").html(site.templating.templates.portfolioContentTemplate.LoadContent(htmlContent));
    },
    
    /// From menu contract: called when the menu open this category
    Close: function () {
        site.portfolio.isOpen = false;
    },
    
    isOpen: false
};